#include "CameraComp.h"
#include <SECore/Ecs/Actor.h>

namespace SEngine
{
    void CameraComp::Attach()
    {
        m_actor.Subscribe<CameraComp, glm::mat4&>("SignalUpdateTransform", [this](glm::mat4 & model) {
            auto pos = m_camera.GetPos();
            auto front = m_camera.GetFront();
            float distance = glm::distance(pos, pos + front);
            m_camera.SetUp(model * glm::vec4{0.0f, 1.0f, 0.0f, 0.0f});
            m_camera.SetFront(model * glm::vec4(1.0f, 0.0f, 0.0f, 0.0f) * distance);
            m_camera.SetPos(model * glm::vec4{0.0f, 0.0f, 0.0f, 1.0f});
            return SlotState::Keep;
        });
    }
} // namespace SEngine

